package main

import (
	"fmt"
	"github.com/gotk3/gotk3/gdk"
	"github.com/gotk3/gotk3/gtk"
	"log"
)

func init() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)
}

func createWin() *gtk.Window {
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}

	file, err := gdk.PixbufNewFromFile("C:\\work\\文档\\tmp\\头像.png")

	win.SetTitle("Simple Example")
	win.SetDefaultSize(200, 200)
	win.SetIcon(file)

	return win
}

func createButton() *gtk.Button {
	buttonNew, err := gtk.ButtonNewWithLabel("点我一下")
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}

	buttonNew.SetTooltipText("你倒是点不点")
	buttonNew.Connect("clicked", func() {
		fmt.Print("我被点了")
	})
	return buttonNew
}

func main() {
	win := createWin()
	buttonNew := createButton()

	adjustmentNew, _ := gtk.AdjustmentNew(33, 33, 33, 33, 33, 33)

	layoutNew, err := gtk.LayoutNew(adjustmentNew, nil)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}

	boxNew, err := gtk.BoxNew(1, 0)

	barNew, err := gtk.MenuBarNew()
	menuNew, err := gtk.MenuNew()
	menuOne, err := gtk.MenuItemNewWithLabel("测试")
	menuTwo, err := gtk.MenuItemNewWithLabel("测试2")

	barNew.Append(menuOne)
	menuOne.SetSubmenu(menuNew)
	menuNew.Append(menuTwo)

	//boxNew.PackStart(barNew,false,false,0)
	boxNew.Add(barNew)

	boxNew2, err := gtk.BoxNew(1, 0)
	boxNew2.Add(buttonNew)

	//layoutNew.Add(boxNew)
	layoutNew.Add(boxNew)
	layoutNew.Add(boxNew2)

	//win.Add(boxNew)
	//win.Add(boxNew2)
	win.Add(layoutNew)

	win.ShowAll()
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	gtk.Main()
}
